<template>
  <div style="padding:3%">
    <el-row>
      <el-col :span="14">
        <el-form :model="form" ref="videoForm" label-width="200px" label-suffix="：">
          <el-form-item v-for="(v,k,i) in form" :label="labels[i]" :key="i" v-if="k!=='netGridID'&&k!=='netGridLeaderName'" :prop="k">
            <el-input-number :min="0" v-if="k=='netGridMemberNumber'||k=='netGridNumber'||k=='netGridArea'" v-model="form[k]"></el-input-number>
            <el-select v-else-if="k=='fatherNetGridID'" v-model="form[k]">
              <el-option v-for="(v,i) in NetGrid" :key="i" :value="v.netGridID" :label="v.netGridName"></el-option>
            </el-select>
            <el-date-picker v-else-if="k=='orgCreateDate'" v-model="form[k]" placeholder="netGridArea"></el-date-picker>
            <el-input v-else v-model="form[k]" style="width:300px"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="update">更新</el-button>
            <el-button type="warning" @click="$router.go(-1)">返回</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import * as api from "@/api/netGridManage";
  import * as api2 from '@/api/zonghezhili/duiwujianshe'
  export default {
    data() {
      return {
        num: 4,
        form: {
          netGridID: '', //            bigint not null auto_increment,
          netGridName: '', //                varchar(100) comment '网格名称',
          netGridLeaderName: '', //          varchar(50) comment '网格长姓名',
          netGridMemberNumber: '', //        int comment '网格成员数量',
          netGridNumber: '', //              int comment '网格户数',
          netGridArea: '', //                int comment '网格面积',
          // fatherNetGridID:''//           bigint comment '上一级网格的ID号，初始值为-1，表示最高网格的编号。',
        },
        labels: ["编号", "网格名称", "网格长姓名", "网格成员数量", "网格户数", "网格面积","上级网格"],
        NetGrid:[]
      };
    },
    methods: {
      reset() {
        for (var key in this.form) {
          this.form[key] = ''
        }
      },
      update() {
        api.updateNetGrid(this.form).then(res => {
          if (res.data) {
            this.$message({
              type: "success",
              message: "添加成功!"
            });
          } else {
            this.$message({
              type: "error",
              message: res.message
            });
          }
        });
      }
    },
    mounted() {
      api.getNetGridDetail(this.$route.query.id).then(res => {
        this.form = res.data
      })
    },created() {
      api2.fetchServedPersonManageTypes().then(res => {
        this.NetGrid = res.data.netGrid
        let item = {
          netGridID:-1,
          netGridName:'开发区管委会(无父级)'
        }
        this.NetGrid.unshift(item);
      })
    }
  };
</script>

<style scoped>

</style>
